//
//  LogoffViewController.swift
//  YunCang
//
//  Created by wangshuning on 16/7/19.
//  Copyright © 2016年 wangshuning. All rights reserved.
//

import UIKit

import MMDrawerController

class LogoffViewController: UIViewController {

    //#MARK: – Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        // Do any additional setup after loading the view.
        let alertC = UIAlertController(title: "提示", message: "真的确认退出登录吗", preferredStyle: UIAlertControllerStyle.alert)
        let action = UIAlertAction(title: "确认退出", style: UIAlertActionStyle.default) { (action: UIAlertAction) in
//            self.quit()
        }
        
        let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel) { (nil) in
        }
        alertC.addAction(action)
        alertC.addAction(cancelAction)
        self.present(alertC, animated: true, completion: nil)
    }
    
    //#MARK: – IBAtions
//    func quit()  {
//        
//        let defaults = NSUserDefaults.standardUserDefaults()
//        defaults.removeObjectForKey("userName")
//        defaults.removeObjectForKey("userPassword")
//        defaults.setBool(false, forKey:"Login")
//        defaults.synchronize()
//
//        let mainVC = LoginViewController()
//        let mianNVC = CenterViewController.init(rootViewController: mainVC)
//        let leftVC = LeftTableViewController()
//        let drawerController = MMDrawerController.init(centerViewController: mianNVC, leftDrawerViewController: leftVC)
//        //                drawerShouldOpen.numberOfCenterViews = 0;
//        mm_drawerController.setCenterViewController(drawerController, withCloseAnimation: true, completion: { (finished:Bool) in
//            
//        }) 
//    }

    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}







//import UIKit
//
//import MMDrawerController
//
//class LoginViewController: UIViewController,UITextFieldDelegate  {
//    
//    @IBOutlet weak var passwordClear: UIButton!
//    @IBOutlet weak var userClear: UIButton!
//    @IBOutlet weak var logoWith: NSLayoutConstraint!
//    @IBOutlet weak var logoImage: UIImageView!
//    @IBOutlet weak var topSpace: NSLayoutConstraint!
//    
//    @IBOutlet weak var centerCon: NSLayoutConstraint!
//    @IBOutlet weak var btnCon: NSLayoutConstraint!
//    @IBOutlet weak var bgCon: NSLayoutConstraint!
//    
//    //    @IBOutlet weak var desLabel: UILabel!
//    @IBOutlet weak var setButton: UIButton!
//    @IBOutlet weak var loginButton: UIButton!
//    @IBOutlet weak var password: UITextField!
//    @IBOutlet weak var userName: UITextField!
//    @IBOutlet weak var lineLabel: UILabel!
//    @IBOutlet weak var bgView: UIView!
//    @IBOutlet weak var imageView: UIImageView!
//    
//    //#MARK: – Lifecycle
//    override func viewDidLoad() {
//        super.viewDidLoad()
//        //读取用户信息
//        self.userName.text = userInfo!.userName
//        // Do any additional setup after loading the view.
//        
//        //遵守UITextFieldDelegate
//        topSpace.constant = KscreenHeight / 667 * 113
//        userName.delegate = self
//        password.delegate = self
//        userName.returnKeyType = UIReturnKeyType.Next
//        password.returnKeyType = UIReturnKeyType.Go
//        password.secureTextEntry = true
//        userClear.hidden = true
//        passwordClear.hidden = true
//        passwordClear.selected = false
//        passwordClear!.setBackgroundImage(UIImage(named: "Cancel-hover"), forState: UIControlState.Highlighted)
//        userClear!.setBackgroundImage(UIImage(named: "Cancel-hover"), forState: UIControlState.Highlighted)
//        userName.tintColor = UIColor.hexStringToUIColor("#00acff")
//        password.tintColor = UIColor.hexStringToUIColor("#00acff")
//        //        获取版本号
//        //                let infoDictionary = NSBundle.mainBundle().infoDictionary
//        //                let appCurVersionNum = infoDictionary!["CFBundleVersion"]
//        //                desLabel.text = "上海海鼎信息工程股份有限公司-v\(appCurVersionNum!)"
//        //设置Button的状态和颜色
//        loginButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Disabled)
//        loginButton.setBackgroundImage(UIImage(named: "矩形-2-拷贝"), forState: UIControlState.Disabled)
//        loginButton.enabled = false
//        
//        //给View添加手势
//        let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(LoginViewController.hideKeyboard))
//        self.view.addGestureRecognizer(gestureRecognizer)
//        
//        //给键盘添加通知
//        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.keyboardShow), name: UIKeyboardWillShowNotification, object: nil)
//        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.keyboardHide), name: UIKeyboardWillHideNotification, object: nil)
//        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.change), name: UITextFieldTextDidChangeNotification, object: self.userName)
//        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.change), name: UITextFieldTextDidChangeNotification, object: self.password)
//        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.userClearchange), name: UITextFieldTextDidChangeNotification, object: self.userName)
//        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.passwordClearchange), name: UITextFieldTextDidChangeNotification, object: self.password)
//        
//        
//    }
//    
//    override func viewWillAppear(animated: Bool) {
//        super.viewWillAppear(animated)
//        password.resignFirstResponder()
//        userName.resignFirstResponder()
//        self.navigationController?.navigationBar.hidden = true
//        self.quitlogin()
//    }
//    
//    //设置状态栏颜色
//    override func preferredStatusBarStyle() -> UIStatusBarStyle {
//        return UIStatusBarStyle.Default
//    }
//    
//    //#MARK:通知方法 – Private Method
//    func userClearchange() {
//        if (userName.text?.characters.count > 0) {
//            userClear.hidden = false
//            
//        }else{
//            userClear.hidden = true
//        }
//    }
//    
//    
//    func passwordClearchange() {
//        if (password.text?.characters.count>0) {
//            passwordClear.hidden = false
//        }else{
//            passwordClear.hidden = true
//        }
//    }
//    
//    func change() {
//        if (userName.text?.characters.count > 0 && password.text?.characters.count>0) {
//            loginButton.enabled = true
//            loginButton.setBackgroundImage(UIImage(named: "矩形-2"), forState: UIControlState.Normal)
//            loginButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
//            
//        }else{
//            loginButton.enabled = false
//            loginButton.setBackgroundImage(UIImage(named: "矩形-2-拷贝"), forState: UIControlState.Disabled)
//        }
//    }
//    //键盘隐藏
//    func hideKeyboard() {
//        userName.resignFirstResponder()
//        password.resignFirstResponder()
//    }
//    
//    //键盘显示的时候，按钮向上跑，不会被遮盖
//    func keyboardShow(textField: UITextField) {
//        //获取键盘的高度
//        //        let userInfo = noti.userInfo as!AnyObject
//        //        let heightValue = userInfo.objectForKey(UIKeyboardFrameEndUserInfoKey)as!NSValue
//        //        let keyboardRect = heightValue.CGRectValue()
//        //        print(keyboardRect.height)
//        //        print(loginButton.y)
//        
//        self.topSpace.constant = KscreenHeight / 667 * 113 - 50
//        self.bgCon.constant = 10*KscreenHeight/320
//        self.btnCon.constant = 10*KscreenHeight/320
//        self.logoWith.constant = 90*KscreenWidth/320
//        
//        UIView.animateWithDuration(0.25, animations: {
//            self.view.layoutIfNeeded()
//        }) { (finished) in
//            
//        }
//    }
//    //收回键盘的方法
//    func keyboardHide() {
//        self.topSpace.constant = KscreenHeight / 667 * 113
//        self.bgCon.constant = 51
//        self.btnCon.constant = 40
//        self.logoWith.constant = 118
//        print(loginButton)
//        UIView.animateWithDuration(0.25, animations: {
//            self.view.layoutIfNeeded()
//        }) { (finished) in
//            
//        }
//    }
//    
//    //#MARK: – UITextFieldDelegate
//    func textFieldShouldReturn(textField: UITextField) -> Bool{
//        if textField == userName {
//            password.becomeFirstResponder()
//        }
//        if textField == password {
//            self.login()
//        }
//        return true
//    }
//    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
//        if textField == userName && userName.text?.characters.count > 0 {
//            userClear.hidden = false
//        }
//        if textField == password && password.text?.characters.count > 0{
//            passwordClear.hidden = false
//        }
//        
//        return true
//    }
//    func textFieldDidEndEditing(textField: UITextField) {
//        
//        if textField == userName {
//            userClear.hidden = true
//        }
//        if textField == password {
//            passwordClear.hidden = true
//        }
//    }
//    
//    //#MARK: – IBAtions
//    @IBAction func passwordClear(sender: AnyObject) {
//        self.password.text = ""
//        passwordClear.hidden = true
//        loginButton.enabled = false
//        loginButton.setBackgroundImage(UIImage(named: "矩形-2-拷贝"), forState: UIControlState.Disabled)
//    }
//    
//    @IBAction func userClear(sender: AnyObject) {
//        self.userName.text = ""
//        userClear.hidden = true
//        loginButton.enabled = false
//        loginButton.setBackgroundImage(UIImage(named: "矩形-2-拷贝"), forState: UIControlState.Disabled)
//    }
//    @IBAction func setButton(sender: AnyObject) {
//        let  setCVC = ServerViewController()
//        self.presentViewController(setCVC, animated: true, completion: nil)
//    }
//    
//    func quitlogin()  {
//        
//        let defaults = NSUserDefaults.standardUserDefaults()
//        defaults.removeObjectForKey("userName")
//        defaults.removeObjectForKey("userPassword")
//        defaults.setBool(false, forKey:"Login")
//        defaults.synchronize()
//        
//    }
//    
//    func retainlogin() {
//        let userDefaults = NSUserDefaults.standardUserDefaults()
//        userDefaults.setObject(userName.text, forKey: "userName")
//        userDefaults.setObject(password.text, forKey: "userPassword")
//        userDefaults.setBool(true, forKey: "Login")
//        userDefaults.synchronize()
//    }
//    
//    
//    @IBAction func loginButton(sender: AnyObject) {
//        self.login()
//    }
//    
//    func login() {
//        if ConfigGlobal.getRootIP().rootIP == nil && ConfigGlobal.getRootIP().IPName == nil {
//            let alert = UIAlertView.init(title: "IP为空或错误", message: "请设置IP", delegate: self, cancelButtonTitle:" 确定")
//            alert.show()
//        } else {
//            
//            passwordClear.hidden = true
//            NetworkTool.sharedTools.postSoap(["Password":EncryptionTool.encryptString(password.text!),"Username":userName.text!], bodyParam: ["piPassWord":password.text!,"piUserName":userName.text!], bodyMethod: "chkUser", success: { responseXml in
//                
//                if (analysisManager.shareManager.XmlParserAnalysis(responseXml, elementName:"chkUserResponse").first!["chkUserResult"]! == "0") {
//                    ConfigGlobal.saveUserInfo(self.userName.text ?? "", userPassWord: self.password.text ?? "")//登陆成功，储存最新的用户信息
//                    self.loginButton.setTitleColor(UIColor.greenColor(), forState: UIControlState.Normal)
//                    let app = UIApplication.sharedApplication()
//                    let app2 = app.delegate;
//                    let  yunCVC = YunCangViewController()
//                    let  centerNVC = YunCenterViewController(rootViewController: yunCVC)
//                    let leftVC = YunLeftTableViewController()
//                    let  drawerController = MMDrawerController.init(centerViewController: centerNVC, leftDrawerViewController: leftVC)
//                    app2?.window!!.rootViewController = drawerController
//                    drawerController?.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.All
//                    drawerController?.maximumLeftDrawerWidth = 270
//                    self.navigationController?.presentViewController(drawerController, animated: true, completion: nil)
//                    self.password.resignFirstResponder()
//                    self.userName.resignFirstResponder()
//                    self.retainlogin()
//                }else {
//                    let alert = UIAlertView.init(title: "用户名或密码错误", message: "请重新登录", delegate: self, cancelButtonTitle:" 确定")
//                    alert.show()
//                }
//                
//            }) {
//                let alert = UIAlertView.init(title: "没有网络或IP设置有误", message: "请检查网络或重新设置IP", delegate: self, cancelButtonTitle:" 确定")
//                alert.show()
//            }
//            
//        }
//        
//        
//    }
//    
//    override func didReceiveMemoryWarning() {
//        super.didReceiveMemoryWarning()
//        // Dispose of any resources that can be recreated.
//    }
//    
//    
//    /*
//     // MARK: - Navigation
//     
//     // In a storyboard-based application, you will often want to do a little preparation before navigation
//     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//     // Get the new view controller using segue.destinationViewController.
//     // Pass the selected object to the new view controller.
//     }
//     */
//    
//}




